package com.hkfn.rfb.rfb.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hkfn.rfb.R;
import com.hkfn.rfb.common.activity.BaseActivity;
import com.hkfn.rfb.common.adapter.BaseRecyclerAdapter;
import com.hkfn.rfb.rfb.bean.RfbSystemOperationModel;

public class RfbSystemOperationAdapter extends BaseRecyclerAdapter<RfbSystemOperationModel> {

    private BaseActivity activity;

    public RfbSystemOperationAdapter(BaseActivity activity) {
        this.activity = activity;
    }

    @Override
    public RecyclerView.ViewHolder onCreate(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(activity).inflate(R.layout.item_rfb_operation_list, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBind(RecyclerView.ViewHolder viewHolder, int RealPosition, RfbSystemOperationModel data) {
        if (viewHolder instanceof MyViewHolder){
            setItemData((MyViewHolder)viewHolder, data, RealPosition);
        }
    }

    private class MyViewHolder extends RecyclerView.ViewHolder{
        private LinearLayout ll_item_content;
        private TextView tv_order_index;
        private TextView tv_order_type;
        private TextView tv_order_start_time;
        private TextView tv_order_start_person;
        private TextView tv_order_device_info;
        private TextView tv_order_status;
        private TextView tv_order_description;
        private TextView tv_order_complete_time;
        private TextView tv_order_opera;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            initItemView(this, itemView);
        }
    }

    private void initItemView(MyViewHolder myViewHolder, View itemView) {
        myViewHolder.ll_item_content = itemView.findViewById(R.id.ll_item_content);
        myViewHolder.tv_order_index = itemView.findViewById(R.id.tv_order_index);
        myViewHolder.tv_order_type = itemView.findViewById(R.id.tv_order_type);
        myViewHolder.tv_order_start_time = itemView.findViewById(R.id.tv_order_start_time);
        myViewHolder.tv_order_start_person = itemView.findViewById(R.id.tv_order_start_person);
        myViewHolder.tv_order_device_info = itemView.findViewById(R.id.tv_order_device_info);
        myViewHolder.tv_order_status = itemView.findViewById(R.id.tv_order_status);
        myViewHolder.tv_order_description = itemView.findViewById(R.id.tv_order_description);
        myViewHolder.tv_order_complete_time = itemView.findViewById(R.id.tv_order_complete_time);
        myViewHolder.tv_order_opera = itemView.findViewById(R.id.tv_order_opera);
    }

    private void setItemData(MyViewHolder viewHolder, RfbSystemOperationModel data, int position) {
        if (position % 2 == 0){
            viewHolder.ll_item_content.setBackgroundColor(activity.getResources().getColor(R.color.transparent));
        }else {
            viewHolder.ll_item_content.setBackgroundColor(activity.getResources().getColor(R.color.rfb_form_data_bg_color));
        }
        viewHolder.tv_order_index.setText(data.get_id()+"");
        viewHolder.tv_order_type.setText(data.obtainTypeStr());
        viewHolder.tv_order_start_time.setText(data.obtainStartTimeStr());
        viewHolder.tv_order_start_person.setText(data.getStartPersonStr());
        viewHolder.tv_order_device_info.setText(data.getDeviceInfo());
        viewHolder.tv_order_status.setText(data.obtainOrderStatusStr());
        viewHolder.tv_order_description.setText(data.getOrderDescription());
        viewHolder.tv_order_complete_time.setText(data.obtainCompleteTimeStr());
    }

}
